package com.security.door.controller.recordInfo;

import com.github.pagehelper.PageInfo;
import com.security.door.core.wrapper.WrapMapper;
import com.security.door.core.wrapper.Wrapper;
import com.security.door.model.domain.recordDoor;
import com.security.door.model.dto.recordDoorDto;
import com.security.door.service.IrecordDoorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@RestController
@Api(value = "WEB - recordDoorController", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class recordDoorController {
    @Autowired
    HttpSession session;
    @Autowired
    HttpServletRequest httpServletRequest;
    @Autowired
    IrecordDoorService irecordDoorService;

    @GetMapping("/record/door/queryListWithPage")
    @ApiOperation(value = "分页查询所有信息", notes = "分页查询所有信息")
    public Wrapper<PageInfo<recordDoor>> listAll() {
        recordDoorDto entityDto = new recordDoorDto();
        int pageIndex = httpServletRequest.getParameter("start") == null ? 0 : Integer.parseInt(httpServletRequest.getParameter("start"));
        int pageSize = httpServletRequest.getParameter("length") == null ? Integer.MAX_VALUE : Integer.parseInt(httpServletRequest.getParameter("length"));
        String searchStr = httpServletRequest.getParameter("search[value]");
        entityDto.setKeyWord(searchStr);
        entityDto.setPageIndex(pageIndex / pageSize + 1);
        entityDto.setPageSize(pageSize);
        var list = irecordDoorService.queryListWithPage(entityDto);
        return WrapMapper.ok(list);
    }

    @GetMapping(value = "/record/deleteOnecardRecord/{guid}")
    public Wrapper deleteOnecardRecord(@PathVariable("guid") String guid) {
        int result = irecordDoorService.deleteByKey(guid);
        return WrapMapper.ok(result);
    }
}
